<style type="text/css">
    .tr_click{
        cursor:pointer;
        background-color:#ccc;
        height: 50px;
        border-bottom: 1px solid #eee;
    }
    .debug_table{
        border: 1px solid #000;
        font-size: 12px;
        margin-top:20px;
        background-color:#eee;
        text-align:left;
    }
    .debug_table th{
        color:#000;
        background-color:#FFCC00;
        padding:10px 10px 10px 10px;
    }
    .tgreen{
        color:green;
    }
    .tblue{
        color:blue;
    }
    .tred{
        color:red;
    }
</style>
<script type="text/javascript">
    function debug_swap_show(id)
    {
        var obj = document.getElementById(id);
        var disp = obj.style.display == 'none' ? '' : 'none';
        obj.style.display = disp;
    }
</script>
<table width="100%" class="debug_table">
    <tr>
        <td width="100" class="tgreen">运行时间:</td><td class="tred" style="text-align:left;"><?php echo round($debugInfo['endTime'] - $debugInfo['beginTime'], 6); ?> 秒</td>
    </tr>

    <?php
    $frontURL = Request::getInstance()->frontUrl();
    if ($frontURL):
        ?>
        <tr>
            <td class="tgreen">来源URL:</td><td class="tblue" style="text-align:left;"><?php echo $frontURL ?></td>
        </tr>
<?php endif; ?>

    <tr>
        <td class="tgreen">当前URL:</td><td class="tblue" style="text-align:left;"><?php echo Request::getInstance()->currentUrl() ?></td>
    </tr>
    <tr>
        <td class="tgreen">控制器:</td><td class="tblue" style="text-align:left;"><?php echo $debugInfo['controller'] ?></td>
    </tr>
    <tr>
        <td class="tgreen">动作方法:</td><td class="tblue" style="text-align:left;"><?php echo $debugInfo['action'] ?></td>
    </tr>
    <tr>
        <td class="tgreen">输出视图:</td><td class="tblue" style="text-align:left;"><?php echo isset($debugInfo['view']) ? $debugInfo['view'] : '&nbsp;' ?></td>
    </tr>
    <tr>
        <td class="tgreen">匹配路由:</td><td class="tblue" style="text-align:left;"><?php echo isset($debugInfo['route']) ? '<pre>' . htmlspecialchars(print_r($debugInfo['route'], true)) . '</pre>' : '&nbsp;' ?></td>
    </tr>

    <tr class="tr_click" onclick="debug_swap_show('tr_sql')">
        <td colspan="2" style="text-align:left;">[SQL]</td>
    </tr>
    <tr style="display:none" id="tr_sql">
        <td colspan="2" style="text-align:left;">
            <?php
            $dbDebugInfo = (array) Registry::getInstance()->get('DB_DEBUG');
            foreach ($dbDebugInfo as $row):
                ?>
                时间:<span class="tred"><?php echo round($row['execTime'], 6) ?></span> 累计:<span class="tred"><?php echo round($row['totalTime'], 6) ?></span> SQL:<span class="tblue"><?php echo $row['sql'] ?></span> <br/>
<?php endforeach; ?>
        </td>
    </tr>

    <tr class="tr_click" onclick="debug_swap_show('tr_param')">
        <td colspan="2" style="text-align:left;">[URI PARAM]</td>
    </tr>
    <tr style="display:none" id="tr_param">
        <td colspan="2" style="text-align:left;"><?php $params = Request::getInstance()->getParam();
if ($params) Sys::dump($params) ?></td>
    </tr>

    <tr class="tr_click" onclick="debug_swap_show('tr_get')">
        <td colspan="2" style="text-align:left;">[GET]</td>
    </tr>
    <tr style="display:none" id="tr_get">
        <td colspan="2" style="text-align:left;"><?php if (isset($_GET) && $_GET) Sys::dump($_GET) ?></td>
    </tr>

    <tr class="tr_click" onclick="debug_swap_show('tr_post')">
        <td colspan="2" style="text-align:left;">[POST]</td>
    </tr>
    <tr style="display:none" id="tr_post">
        <td colspan="2" style="text-align:left;"><?php if (isset($_POST) && $_POST) Sys::dump($_POST) ?></td>
    </tr>

    <tr class="tr_click" onclick="debug_swap_show('tr_cookie')">
        <td colspan="2" style="text-align:left;">[COOKIE]</td>
    </tr>
    <tr style="display:none" id="tr_cookie">
        <td colspan="2" style="text-align:left;"><?php if (isset($_COOKIE) && $_COOKIE) Sys::dump($_COOKIE) ?></td>
    </tr>

    <tr class="tr_click" onclick="debug_swap_show('tr_session')">
        <td colspan="2" style="text-align:left;">[SESSION]</td>
    </tr>
    <tr style="display:none" id="tr_session">
        <td colspan="2" style="text-align:left;"><?php if (isset($_SESSION) && $_SESSION) Sys::dump($_SESSION) ?></td>
    </tr>

    <tr class="tr_click" onclick="debug_swap_show('tr_files')">
        <td colspan="2" style="text-align:left;">[FILES]</td>
    </tr>
    <tr style="display:none" id="tr_files">
        <td colspan="2" style="text-align:left;"><?php if (isset($_FILES) && $_FILES) Sys::dump($_FILES) ?></td>
    </tr>

    <tr class="tr_click" onclick="debug_swap_show('tr_server')">
        <td colspan="2" style="text-align:left;">[SERVER]</td>
    </tr>
    <tr style="display:none" id="tr_server">
        <td colspan="2" style="text-align:left;"><?php Sys::dump($_SERVER) ?></td>
    </tr>

    <tr class="tr_click" onclick="debug_swap_show('tr_viewvar')">
        <td colspan="2" style="text-align:left;">[视图变量]</td>
    </tr>
    <tr style="display:none" id="tr_viewvar">
        <td colspan="2" style="text-align:left;">
            <?php

            // 处理数据为友好显示
            function debug_dataShow($val) {
                if (is_array($val)) {
                    return array_map('debug_dataShow', $val);
                } elseif (is_object($val)) {
                    return get_class($val) . ' Object';
                } elseif (is_resource($val)) {
                    return get_resource_type($val);
                } else {
                    return toHtml($val);
                }
            }

            $viewDebugInfo = Registry::getInstance()->get('VIEW_DEBUG');
            if (is_array($viewDebugInfo)) {
                $content = array_map('debug_dataShow', $viewDebugInfo);
            }
            Sys::dump($content);
            ?>
        </td>
    </tr>

    <tr class="tr_click" onclick="debug_swap_show('tr_includepath')">
        <td colspan="2" style="text-align:left;">[搜索路径]</td>
    </tr>
    <tr style="display:none" id="tr_includepath">
        <td colspan="2" style="text-align:left;"><?php Sys::dump(explode(PATH_SEPARATOR, get_include_path())) ?></td>
    </tr>

    <tr class="tr_click" onclick="debug_swap_show('tr_includefile')">
        <td colspan="2" style="text-align:left;">[引入文件]</td>
    </tr>
    <tr style="display:none" id="tr_includefile">
        <td colspan="2" style="text-align:left;"><?php Sys::dump(get_included_files()) ?></td>
    </tr>

    <tr class="tr_click" onclick="debug_swap_show('tr_extensions')">
        <td colspan="2" style="text-align:left;">[安装的扩展]</td>
    </tr>
    <tr style="display:none" id="tr_extensions">
        <td colspan="2" style="text-align:left;"><?php Sys::dump(get_loaded_extensions()) ?></td>
    </tr>

</table>
